package com.treeroot.treenet.enums;

import com.treeroot.treenet.common.base.BaseEnum;
import lombok.AllArgsConstructor;

/**
 * Create By TreeRoot
 * Create Time: 2023/12/18 03:40
 * Class Name: RequestMethodTypeMenu
 * Description:
 * 请求方法枚举
 *
 * @author TreeRoot
 */
@AllArgsConstructor
public enum RequestMethodTypeMenu implements BaseEnum {
    /**
     * get
     */
    GET("0", "GET"),
    /**
     * post
     */
    POST("1", "POST"),
    /**
     * put
     */
    PUT("2", "PUT"),
    /**
     * delete
     */
    DELETE("3", "DELETE"),
    /**
     * option
     */
    OPTIONS("4", "OPTIONS");

    private final String key;
    private final String value;

    @Override
    public String getKey() {
        return key;
    }

    @Override
    public String getValue() {
        return value;
    }

    /**
     * 按键获取值
     *
     * @param key key
     * @return str
     * 2023/11/06
     */
    public static String getValueByKey(String key) {
        for (RequestMethodTypeMenu requestMethodTypeMenu : RequestMethodTypeMenu.values()) {
            if (requestMethodTypeMenu.getKey().equals(key)) {
                return requestMethodTypeMenu.getValue();
            }
        }
        return null;
    }

    /**
     * 按值获取键
     *
     * @param value value
     * @return str
     * 2023/11/06
     */
    public static String getKeyByValue(String value) {
        for (RequestMethodTypeMenu requestMethodTypeMenu : RequestMethodTypeMenu.values()) {
            if (requestMethodTypeMenu.getValue().equals(value)) {
                return requestMethodTypeMenu.getKey();
            }
        }
        return null;
    }

}
